//思路：双指针

import java.sql.Array;
import java.util.*;

public class Solution {
    public static void main(String[] args) {
        String s="abcdefg";
        System.out.println(reverseStr(s,2));
    }

    public static String reverseStr(String s, int k) {
        char[] c=s.toCharArray();
        if(c.length<k){
            reverseString(c,0,c.length-1);
        }else if (c.length>=k&&c.length<2*k) {
            reverseString(c,0,k-1);

        }else {
            int sublen= c.length;
            int i=0;
            do{
                reverseString(c,i,i+k-1);
                i=i+2*k;
                sublen-=2*k;

            }while(sublen>=2*k);
            if(sublen<k){
                if(sublen!=0) {
                    reverseString(c, i, c.length - 1);
                }

            } else if (sublen>=k) {
                reverseString(c,i,i+k-1);
            }
        }
       s=new String(c);
        return s ;

    }
    public static void  reverseString(char[] s,int i,int j) {
          while(i<j){
              char t=s[i];
              s[i]=s[j];
              s[j]=t;
              j--;
              i++;
          }

    }
    

}













